/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.server.modules.sys.web.loan;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.server.common.config.Global;
import com.server.common.persistence.Page;
import com.server.common.web.BaseController;
import com.server.common.utils.StringUtils;
import com.server.modules.sys.entity.loan.LoanTags;
import com.server.modules.sys.service.loan.LoanTagsService;

/**
 * 产品标签管理Controller
 * @author 王磊
 * @version 2016-09-09
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/loan/loanTags")
public class LoanTagsController extends BaseController {

	@Autowired
	private LoanTagsService loanTagsService;
	
	@ModelAttribute
	public LoanTags get(@RequestParam(required=false) String id) {
		LoanTags entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = loanTagsService.get(id);
		}
		if (entity == null){
			entity = new LoanTags();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:loan:loanTags:view")
	@RequestMapping(value = {"list", ""})
	public String list(LoanTags loanTags, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<LoanTags> page = loanTagsService.findPage(new Page<LoanTags>(request, response), loanTags); 
		model.addAttribute("page", page);
		model.addAttribute("loanTags", loanTags);
		return "modules/sys/loan/loanTagsList";
	}

	@RequiresPermissions("sys:loan:loanTags:view")
	@RequestMapping(value = "form")
	public String form(LoanTags loanTags, Model model) {
		model.addAttribute("loanTags", loanTags);
		return "modules/sys/loan/loanTagsForm";
	}

	@RequiresPermissions("sys:loan:loanTags:edit")
	@RequestMapping(value = "save")
	public String save(LoanTags loanTags, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, loanTags)){
			return form(loanTags, model);
		}
		loanTagsService.save(loanTags);
		addMessage(redirectAttributes, "保存产品标签成功");
		return "redirect:"+Global.getAdminPath()+"/sys/loan/loanTags/?repage";
	}
	
	@RequiresPermissions("sys:loan:loanTags:edit")
	@RequestMapping(value = "delete")
	public String delete(LoanTags loanTags, RedirectAttributes redirectAttributes) {
		loanTagsService.delete(loanTags);
		addMessage(redirectAttributes, "删除产品标签成功");
		return "redirect:"+Global.getAdminPath()+"/sys/loan/loanTags/?repage";
	}

}